package cn.itbox.example.application.test.four.annotationTest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.Arrays;

@Component
public class AnnotationExecutor {

    @Autowired
    private MyService myService;

    public void executeMyAnnotatedMethods() {
        Method[] methods = myService.getClass().getDeclaredMethods();
        Arrays.stream(methods)
                .filter(method -> method.isAnnotationPresent(MyAnnotation.class))
                .forEach(method -> {
                    try {
                        method.invoke(myService);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
    }
}